package com.hspedu.newData.dmsxl.数组.区间;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-09 
 * @Version: 1.0
 */

public class LC228汇总区间 {

    // todo 效率不高
    public List<String> summaryRanges(int[] nums) {

        List<String> list = new ArrayList<>();

        if (nums.length == 0) return list;

        for (int i = 0; i < nums.length; i++) {
            int start = nums[i];

            while (i < nums.length - 1 && nums[i+1]-nums[i]==1){
                i++;
            }
            int end = nums[i];
            if (end-start > 0){
                list.add(start+"->"+end);
            }else {
                list.add(start+"");
            }
        }


        return list;

    }

    @Test
    public void test() {
        // 测试代码

        summaryRanges(new int[]{0,2,3,4,6,8,9});

    }

}
